import sqlite3
import os

class config(object):
    def __init__(self):
	home =os.environ['HOME']
	datapath = home + "/.gnome2/rhythmbox/plugins/artdisplay/"
        self.conn = sqlite3.connect(datapath +"config.db")
        self.cur = self.conn.cursor()
    def  close(self):
        self.cur.close()
     
    def writeconfig(self, name, value):
        sql ="select config_value from config where config_name ='"+name+"'"
        self.cur.execute(sql)
        if self.cur.rowcount == 0:
            sql ="insert into config values('"+name+"','"+value+"')"
            self.cur.execute(sql)
        else:
            sql ="update config set config_value ='"+value+"' where config_name = '"+name+"'"
            self.cur.execute(sql)
        self.conn.commit()
    def readconfig(self, name):
        sql ="select config_value from config where config_name = '"+name+"'"
        self.cur.execute(sql)
        self.conn.commit()
        return self.cur.fetchone()[0]

#if __name__ =="__main__":
    #conf = config()
    #conf.writeconfig("name", "sldf")
    #conf.close()
